import { useState } from "react";

type Fn1 = (id: number) => void;
type Fn2 = () => void;

export default function useVisible(getDetail: Fn1, getList: Fn2) {
	// 详情
	const [detailVisible, setDetailVisible] = useState(false);
	const openDetail = (id: number) => {
		// 获取详情
		getDetail(id);
		setDetailVisible(true);
	};

	// 修改
	const [editVisible, setEditVisible] = useState(false);
	const openEdit = async (id: number) => {
		getDetail(id);
		setEditVisible(true);
	};
	const onCloseEdit = () => {
		getList();
		setEditVisible(false);
	};

	// 新增
	const [addVisible, setAddVisible] = useState(false);
	const onCloseAdd = () => {
		getList();
		setAddVisible(false);
	};

	return {
		detailVisible,
		setDetailVisible,
		editVisible,
		setEditVisible,
		addVisible,
		setAddVisible,
		openDetail,
		openEdit,
		onCloseEdit,
		onCloseAdd
	};
}
